#!/bin/bash
function download_and_update_cursor() {
	url=$1
	dst=$2
	if [ -z "${url}" ]; then
		url=https://dl.todesktop.com/230313mzl4w4u92/linux/appImage/x64
	fi
	if [ -z "${dst}" ]; then
		dst=/usr/local/bin/cursor
	fi
	cache='/tmp/cursor'
	if [ ! -f "${cache}" ]; then
		wget -c "$url" -O "$cache"
	fi
	chmod a+x "$cache"
	if [ -f "${dst}" ]; then
		cp "${cache}" ${dst}
	else
		old_hash=$(md5sum ${dst} | cut -d " " -f1)
		new_hash=$(md5sum ${cache} | cut -d " " -f1)
		if [ "${old_hash}" != "${new_hash}" ]; then
			cp $cache $dst
		fi
	fi

}
function download_and_update() {
	software=$1
	case $software in
	cursor)
		download_and_update_cursor
		;;
	wolai)
		download_and_update_wolai
		;;
	*) ;;
	esac
}
download_and_update $@
